Skip to content

Conversation

@mingquan5830
Copy link
Contributor

@mingquan5830 mingquan5830 commented Dec 19, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

--

💡 需求背景和解决方案

需求背景

Taro 版本的 Avatar 组件中,fit 属性使用 style={{ objectFit: fit }} 实现,但 Taro Image 组件在小程序端不支持 CSS object-fit,需要使用原生的 mode 属性,因此当前 fit 属性不生效。但鉴于这是一个常用的能力,所以需要支持。

解决方案

通过Taro中的 Image mode 属性来支持Avatar组件的图片填充模式。

Taro官方文档中 Image mode 属性相关信息如下:
image
image
image
image

可以看到API支持程度很好

其他说明

  1. 属性名为 mode 是为了对齐Taro,并且mode 默认值为 scaleToFill(与 Taro Image 默认值保持一致,避免 breaking change)
  2. 移除了无效的 fit 属性

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • Avatar 组件新增 mode 属性,支持多种图片缩放/裁剪模式(默认 scaleToFill),提升图片显示灵活性。
  • 文档

    • 增加模式演示示例,展示不同 image mode 效果。
    • 更新组件文档和属性表,新增 mode,标注旧的 fit 使用为已弃用并调整 onClick 事件类型为触摸事件签名。

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) and removed 3.x Target branch 3.x labels Dec 19, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Walkthrough

新增 Avatar 的公有属性 mode(默认 scaleToFill),Image 渲染同时保留现有 fit 使用;添加 demo10 展示多种 image mode,更新文档与类型定义并将 onClick 类型改为 ITouchEvent

Changes

Cohort / File(s) 变更摘要
核心组件
src/packages/avatar/avatar.taro.tsx
新增公有 prop mode(默认 scaleToFill),从 props 解构并传给 Image(同时保留 fit 的原有处理),扩展组件 API。
演示与多语言
src/packages/avatar/demo.taro.tsx
在 AvatarDemo 中新增 demo10 节点并引入 Demo10,新增多语言键 imageModezh-CN / zh-TW / en-US)。
新增 demo 文件
src/packages/avatar/demos/taro/demo10.tsx
新建 Demo10 组件,渲染四个 Avatar 示例,分别展示 scaleToFillaspectFitaspectFillwidthFix
文档
src/packages/avatar/doc.taro.md
在 Props 表中加入 mode 条目(可选值集合、默认 scaleToFill),新增“图片填充模式”示例代码块;将 onClick 类型从 MouseEvent 改为 ITouchEvent
类型定义
src/types/spec/avatar/taro.ts
引入 ImageProps,在 TaroAvatarProps 中新增 mode: keyof ImageProps.Mode,保留并标注 fit 为弃用/兼容项。

Estimated code review effort

🎯 3 (中等) | ⏱️ ~20 minutes

Suggested reviewers

  • oasis-cloud
  • irisSong

Poem

🐰 新模入列映头像,mode与fit共相邀,
四态演示行间舞,文档类型亦更新,
触屏回调换新名,轻声跳跃报喜哉。

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地总结了主要变动:为 Taro Avatar 组件添加图片填充模式支持,符合 feat(avatar): 的特性提交格式。
Description check ✅ Passed 描述完整,包含变动性质、需求背景、解决方案、相关文档和自检清单,所有必需部分都已填写。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cac7ec5 and 0683497.

📒 Files selected for processing (2)
  • src/packages/avatar/avatar.taro.tsx
  • src/types/spec/avatar/taro.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/packages/avatar/avatar.taro.tsx
  • src/types/spec/avatar/taro.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.15%. Comparing base (b6b0345) to head (0683497).
⚠️ Report is 3 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3405   +/-   ##
==========================================
  Coverage      88.15%   88.15%           
==========================================
  Files            291      291           
  Lines          19212    19212           
  Branches        2988     2988           
==========================================
  Hits           16937    16937           
  Misses          2269     2269           
  Partials           6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/packages/avatar/demos/taro/demo10.tsx (1)

1-16: Demo 实现正确,展示了不同的图片填充模式

Demo10 组件正确使用了新的 mode 属性,展示了四种常用的图片填充模式。实现简洁清晰。

可选建议:为了更好地展示不同 mode 的视觉效果

考虑使用一张非正方形的图片(例如宽高比明显不同的图片),这样可以更清楚地展示不同 mode 之间的差异。当前使用的图片如果接近正方形,某些 mode(如 aspectFit 和 aspectFill)的视觉差异可能不够明显。

例如:

 const Demo10 = () => {
+  // 使用宽高比差异明显的图片以更好地展示不同 mode 的效果
   const src =
-    'https://storage.360buyimg.com/imgtools/e067cd5b69-07c864c0-dd02-11ed-8b2c-d7f58b17086a.png'
+    'https://example.com/wide-image.png'  // 使用一张宽度明显大于高度的图片

这是一个可选的改进建议,当前实现已经足够展示功能。

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6b0345 and cac7ec5.

📒 Files selected for processing (5)
  • src/packages/avatar/avatar.taro.tsx (3 hunks)
  • src/packages/avatar/demo.taro.tsx (5 hunks)
  • src/packages/avatar/demos/taro/demo10.tsx (1 hunks)
  • src/packages/avatar/doc.taro.md (2 hunks)
  • src/types/spec/avatar/taro.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/packages/avatar/demos/taro/demo10.tsx (1)
src/packages/avatar/avatar.taro.tsx (1)
  • Avatar (32-177)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (8)
src/packages/avatar/demo.taro.tsx (1)

16-16: 新增 Demo10 集成看起来不错

新增的 Demo10 导入、翻译键和渲染逻辑都正确实现,为新的图片填充模式功能提供了完整的演示支持。

Also applies to: 30-30, 42-42, 55-55, 83-84

src/packages/avatar/avatar.taro.tsx (2)

25-25: 默认值更改为 'scaleToFill' 是正确的选择

将默认值从 fit: 'cover' 改为 mode: 'scaleToFill' 符合 Taro Image 组件的原生默认行为,有助于保持向后兼容性。这个选择很合理。


43-43: 使用 Taro 原生 mode 属性解决了小程序兼容性问题

fit 属性替换为 mode 属性,并在 Image 组件上使用 mode={mode} 而不是 style={{ objectFit: fit }},正确解决了 CSS objectFit 在小程序平台不生效的问题。这是使用 Taro Image 原生能力的正确做法。

Also applies to: 132-132

src/packages/avatar/doc.taro.md (3)

93-99: 新增的图片填充模式文档部分结构清晰

新增的文档部分正确引用了 demo10,为用户提供了可视化的示例。


114-114: onClick 签名更新正确反映了 Taro 环境

将 onClick 的事件类型从 MouseEvent<HTMLDivElement> 更新为 ITouchEvent 正确反映了 Taro 环境的触摸事件模型,这个更新是必要且正确的。


112-112: Documentation accuracy for mode attribute values confirmed

The mode attribute values listed are accurate and match the Taro Image component specification. The complete set includes 4 primary scaling modes (scaleToFill, aspectFit, aspectFill, widthFix), 1 additional scaling mode (heightFix), and 9 cropping modes (top, bottom, center, left, right, top left, top right, bottom left, bottom right). These values are consistent with the WeChat mini-program Image component standard that Taro follows.

src/types/spec/avatar/taro.ts (2)

1-1: 确认 Taro 4.0.12 中 ImageProps.Mode 类型模式的有效性

需要在项目中验证 keyof ImageProps.Mode 是否为正确的 TypeScript 类型推导模式。Taro Image 组件的 mode 属性支持 13 种模式,包括 4 种缩放模式(scaleToFill、aspectFit、aspectFill、widthFix)和 9 种裁剪模式(top、bottom、center、left、right、top-left、top-right、bottom-left、bottom-right),但应确保类型定义能够准确推断这些所有可用值。建议在 node_modules/@tarojs/components/types 中查看实际的 ImageProps 和 Mode 类型定义,或通过 TypeScript 编译器验证该模式是否产生预期的类型推导结果。


4-4: 验证完成:TaroAvatarProps 中 fit 属性的移除是正确和必要的

TaroAvatarPropsBaseAvatar 中移除 'fit' 属性的设计是合理的。Taro 使用不同的 Image 组件 API,采用 mode 属性进行图片缩放处理(如 scaleToFill),而非 Web 端的 CSS object-fit 属性。代码库中未发现任何遗留的 fit 属性引用,avatar.taro.tsx 实现完整且与 Taro Image 组件 API 一致。

icon: '',
background: '#eee',
color: '#666',
fit: 'cover',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以不要直接删除,先加一个 待废弃 标志吧~~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好啦~

@github-actions github-actions bot added the 3.x Target branch 3.x label Dec 24, 2025
@xiaoyatong xiaoyatong merged commit 2060383 into jdf2e:feat_v3.x Dec 25, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants